<template>
  <view class="pay0test tn-safe-area-inset-bottom">
    <tn-navbar z-index="1" index-url="/pages/index" fixed :bottom-shadow="false" :is-back="false">正在支付</tn-navbar>
    <tn-button @click="payTest">测试支付</tn-button>
    <tn-toast ref="toast"></tn-toast>
  </view>
</template>

<script setup lang="ts">
import { onMounted, ref, reactive } from "vue";

import TnNavbar from "@/tuniao-ui/components/tn-navbar/src/Navbar.vue";
import TnButton from "@/tuniao-ui/components/tn-button/src/Button.vue";
import TnToast from "@/tuniao-ui/components/tn-toast/src/Toast.vue";
import { getOpenId } from "@/api/user";
const toast = ref<InstanceType<typeof TnToast>>();

function payTest() {


  var wxurl = window.location.search;
  var theRequest = new Object();
  if (wxurl.indexOf("?") != -1) {
    var str = wxurl.substr(1);
    var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
    }
  }
  console.log(theRequest);
  //   console.log("支付测试");
  //   uni.request({
  //     method: "GET",
  //     url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98be844de541a102&redirect_uri=http://xinlong.natapp1.cc/#/pages/mine/order/pay&response_type=code&scope=SCOPE&state=STATE#wechat_redirect",
  //     success(res) {
  //      console.log(res);
  //     },
  //   });
  let redirectUri = "http://xinlong.natapp1.cc/#/pages/mine/order/pay?id=30";
  redirectUri = encodeURIComponent(redirectUri);
  let url =
    "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98be844de541a102&redirect_uri=" +
    redirectUri +
    "&response_type=code&scope=snsapi_base&state=code#wechat_redirect";
  //url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98be844de541a102&redirect_uri=http://xinlong.natapp1.cc&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
//https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98be844de541a102&redirect_uri=http://xinlong.natapp1.cc#/pages/mine/order/buyerOrder?id=30&response_type=code&scope=snsapi_base&state=123#wechat_redirect
  console.log(url);
  //location.href = url;
  // let code = "051TOz0w3sOOj03v0v2w3fvseO3TOz02";
  // getOpenId({ code: code }).then((result) => {
  //   console.log(result);
  //   WeixinJSBridge.invoke(
  //     "getBrandWCPayRequest",
  //     result.result,
  //     function (res) {
  //       if (res.err_msg == "get_brand_wcpay_request:ok") {
  //         // 使用以上方式判断前端返回,微信团队郑重提示：
  //         //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
  //         toast.value?.show({
  //           title: "支付成功",
  //         });
  //       }
  //     }
  //   );
  // });
  //openId = oFx6L6BQzlf9CU0HZtUJ16duMeHI
}
</script>

<style lang="scss" scoped></style>
